﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8" />
    <title>查询</title>
    <link href="../Scripts/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <link href="../Scripts/bootstrap/css/font-awesome.css" rel="stylesheet" />
    <link href="../Scripts/bootstrap/bootstrap-table/src/bootstrap-table.css" rel="stylesheet"
        type="text/css" />
    <link href="../Scripts/bootstrap/css/style.min.css" rel="stylesheet" type="text/css"
        media="all" />
    <!--jquery-->
    <script src="../Scripts/jquery-1.11.0.min.js" type="text/javascript"></script>
    <script src="../Scripts/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
    <script src="./JS/layer/layer.js" type="text/javascript"></script>
    <link href="./JS/layer/layer.css" rel="stylesheet" type="text/css" />
    <!--bootstrap-table-->
    <script src="../Scripts/bootstrap/bootstrap-table/src/bootstrap-table.js" type="text/javascript"></script>
    <script src="../Scripts/bootstrap/bootstrap-table/src/locale/bootstrap-table-zh-CN.js"
        type="text/javascript"></script>
    <script src="../Scripts/bootstrap/BootstrapUIDialog.js" type="text/javascript"></script>
    <script src="../Scripts/bootstrap/bootstrap-paginator/js/bootstrap-paginator.js"
        type="text/javascript"></script>
    <!--公共JS-->
    <script src="../Scripts/QueryString.js" type="text/javascript"></script>
    <script src="../Scripts/config.js" type="text/javascript"></script>
    <script src="Gener.js" type="text/javascript"></script>
    <script language="JavaScript" src="JScript.js" type="text/javascript"></script>
    <script src="../Comm/JS/Calendar/WdatePicker.js" type="text/javascript"></script>
    <link href="../Comm/JS/Calendar/skin/WdatePicker.css" rel="stylesheet" type="text/css" />
    <script src="../Admin/CCFlowEnum.js" type="text/javascript"></script> 
    <script src="../CCForm/MapExt2016.js" type="text/javascript"></script>   
    <!--serach页面JS开发接口-->
    <script src="../../DataUser/JSLibData/SearchSelf.js" type="text/javascript"></script>
    <base target="_self" />
    <style type="text/css">
        .Wdate
        {
            border: 1px solid #e5e6e7;
            height: 28px;
        }
        .fixed-table-container thead th .th-inner
        {
            padding: 8px;
            line-height: 24px;
            vertical-align: top;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap; /**background-color: #eaf2ff;**/
            width: 100%;
        }
        .fixed-table-header
        {
            background-color: #f2f2f2;
        }
        
        td
        {
            word-break: keep-all; /* 不换行 */
            white-space: nowrap; /* 不换行 */
            overflow: hidden; /* 内容超出宽度时隐藏超出部分的内容 */
            text-overflow: ellipsis; /* 当对象内文本溢出时显示省略标记(...) ；需与overflow:hidden;一起使用*/
            -o-text-overflow: ellipsis;
            -icab-text-overflow: ellipsis;
            -khtml-text-overflow: ellipsis;
            -moz-text-overflow: ellipsis;
            -webkit-text-overflow: ellipsis;
        }
    </style>
    <script language="javascript" type="text/javascript">
        var ensName = GetQueryString("EnsName");

        //定义公共个变量.
        var webUser = new WebUser();

         //页面设置信息
        var cfg = new Entity("BP.Sys.EnCfg");
        cfg.No = ensName;
        cfg.RetrieveFromDBSources();

        //当前用户查询信息.
        var ur = new Entity("BP.Sys.UserRegedit");
        ur.MyPK = webUser.No + "_" + ensName + "_SearchAttrs";
        ur.RetrieveFromDBSources();

        var count = ur.GetPara("RecCount");//查询总条数
        var mapBase;
        var pageIdx = this.GetQueryString("PageIdx");//当前页

        var pageSize = cfg.GetPara("PageSize");
        if(pageSize == null || pageSize == undefined || pageSize ==0)
            pageSize = 10;//一页显示的行数

        var pages = 1;//总页数
        if (count%pageSize!=0)
            pages = parseInt(count / pageSize) + 1;
        else
            pages = parseInt(count / pageSize);
        if(pages == 0) pages =1;

        //页面字体大小
        var fontSize = cfg.GetPara("FontSize");
        if(fontSize == null || fontSize == undefined || fontSize ==0)
            fontSize = 13;
      

      var firstLoadTable = false;

        //页面启动函数.
        $(function () {

            if (webUser.No == undefined) {
                alert('登录信息丢失，请重新登录。');
                return;
            }

            if (ensName == null || ensName == undefined) {
                $("#Msg").html("必要的参数EnsName没有传入.");
                return;
            }

            $("#Msg").html("<img src=../Img/loading.gif />&nbsp;正在加载,请稍后......");

            $("#dialogExpFile").hide();
            //初始化工具栏.
            InitToolbar();
            //执行查询.
            BindTable();
            $("#Msg").html("");

              $("td").on("mouseover",function() {
                if (this.offsetWidth < this.scrollWidth) {
                    var that = this;
                    var text = $(this).text();
                   layer.tips(text, that,{
                        tips: 1,
                        time: 0
                   });
                }
              });
              $("td").on("mouseout",function(){
                layer.closeAll();
              });
            
            if(pageIdx==null || pageIdx==undefined || pageIdx == "")
                pageIdx = 1;
            //分页
            Paginator(pages,pageIdx);
            $("#SearchHtml").css("font-size", fontSize+"px");
           
        });

        //初始化数据.
        function InitToolbar() {

            //创建处理器.
            var handler = new HttpHandler("BP.WF.HttpHandler.WF_Comm");
            handler.AddUrlData();  //增加参数.
            //获得map基本信息.
            mapBase = handler.DoMethodReturnJSON("Search_MapBaseInfo");

            // $("#Title").html(mapBase.EnDesc);
            document.title = mapBase.EnDesc;

            //获得查询信息，包含了查询数据表.
            var data = handler.DoMethodReturnJSON("Search_SearchAttrs");
            
            var barCount = 0; //记录查询条件，超过五个就换行
            var IsTableShow = false;
             //绑定外键枚举查询条件.
            var attrs = data["Attrs"];
            if(attrs.length>0){
                for(var i = 0; i < attrs.length; i++){
                    if(attrs[i].Width>=1000){
                        IsTableShow = true;
                        break;
                    }

                }
            }
            var html = "";
            if(IsTableShow || 1==1){
               showBarTable(attrs,data);
               return;
            }
           
            if (mapBase.IsShowSearchKey == "1"){
                var keyLabel  = cfg.GetPara("KeyLabel");
                if(keyLabel == null || keyLabel == undefined || keyLabel =="")
                    keyLabel="关键字";
                html += "<label  style='text-align: right; margin-top:5px;margin-left:5px;' for='TB_Key'>"+keyLabel+":&nbsp;&nbsp</label>"
                html +="<input style='width:140px;' type=text id='TB_Key' name='TB_Key' value='" + ur.SearchKey + "' class='form-control' />";
                barCount += 1;
            }

            if (mapBase.DTSearchWay != "0") {
            	barCount += 2;
                html += "<label style='text-align: right; margin-top:5px;padding-left:20px;'>" + mapBase.DTSearchLable + ":&nbsp;&nbsp</label>";

                if (mapBase.DTSearchWay == "1") {
                    html += "<input type=text id='TB_DTFrom' name='TB_DTFrom' value='" + ur.DTFrom + "'  onfocus=\"WdatePicker({dateFmt:'yyyy-MM-dd'})\" style='width:120px;' class='form-control' />";
                    html += "&nbsp;&nbsp;<label>到</label>&nbsp;&nbsp<input type=text id='TB_DTTo' name='TB_DTTo' value='" + ur.DTTo + "' onfocus=\"WdatePicker({dateFmt:'yyyy-MM-dd'})\" style='width:140px;' class='form-control' />";
                } else {
                    html += "<input type=text id='TB_DTFrom' name='TB_DTFrom' value='" + ur.DTFrom + "'  onfocus=\"WdatePicker({dateFmt:'yyyy-MM-dd HH:mm'});\" style='width:140px;' class='form-control' />";
                    html += "&nbsp;&nbsp;<label>到</label>&nbsp;&nbsp<input type=text id='TB_DTTo' name='TB_DTTo' value='" + ur.DTTo + "' onfocus=\"WdatePicker({dateFmt:'yyyy-MM-dd HH:mm'});\"  style='width:120px;' class='form-control' />";
                }
            }
			
            $("#toolbar").append(html); //设置基础信息.

            //格式为: @WFSta=0@FK_Dept=02
            var json = AtParaToJson(ur.Vals);
            
            for (var i = 0; i < attrs.length; i++) {
            	 var attr = attrs[i];
                 var str = "";
					
                str += "<label style='text-align: right; margin-top:5px;margin-left:5px;' for='DDL_" + attr.Field + "'>" + attr.Name + ":</label>";

                str += "<select class='form-control' style='margin-top:5px;width:"+attr.Width+"px' name='DDL_" + attr.Field + "' ID='DDL_" + attr.Field + "'>" + InitDDLOperation(data, attr, "all") + "</select>";
                str = $(str);
              
                barCount += 1;
                
                $("#toolbar").append(str); //设置基础信息.
            }
            
            html="";
            //为查询外键赋值.
            for (var i = 0; i < attrs.length; i++) {
                var attr = attrs[i];
                 var selectVal = json[attr.Field];

                if (selectVal == undefined || selectVal == "")
                    selectVal = "all";

                //判断是否有级联关系
                var myPK = "ActiveDDL_"+ensName+"_"+attr.Field;
                var mapExt = new Entity("BP.Sys.MapExt");
                mapExt.SetPKVal(myPK);
                var isExist = mapExt.RetrieveFromDBSources();
                //处理级联关系
                if(isExist == 1){
                    var ddlPerant = $("#DDL_" + mapExt.AttrOfOper);
                    var ddlChild = $("#DDL_" + mapExt.AttrsOfActive);
                    if (ddlPerant != null && ddlChild != null){
                        ddlPerant.attr("onchange", "DDLRelation(this.value,\'" + "DDL_" + mapExt.AttrsOfActive + "\', \'" + mapExt.MyPK + "\',\'" + ddlPerant.val() + "\')");
                       
                    }
                }
                
                $("#DDL_" + attr.Field).val(selectVal);
            }
            
            html += '<a href="#"class="btn btn-primary btn-sm" style="margin-left:20px" id="search_btn" onclick="Search()">查询</a>  ';
           var btnLab1 = cfg.GetPara("BtnLab1");
            var btnLab2 = cfg.GetPara("BtnLab2");
            if(btnLab1 != null && btnLab1 != undefined && btnLab1 != "")
                html += "&nbsp;<a href='#'class='btn btn-default btn-sm'   onclick='executeFunction(\""+cfg.GetPara("BtnJS1")+"\",\""+btnLab1+"\")'>"+btnLab1+"</a>";

             if(btnLab2 != null && btnLab2 != undefined && btnLab2 != "")
                 html += "&nbsp;<a href='#'class='btn btn-default btn-sm'   onclick='executeFunction(\""+cfg.GetPara("BtnJS2")+"\",\""+btnLab2+"\")'>"+btnLab2+"</a>";
            
            if (mapBase.IsInsert.toString().toLowerCase() == "true") {
                html += '<a href="#" class="btn btn-default btn-sm" id="new_btn" onclick="New()">新建</a>  ';
            } 
			html +='<a href="#" class="btn btn-default btn-sm" id="exp_btn" onclick="Exp()">导出</a>  ';

            if(mapBase.IsImp.toString().toLowerCase() == "true")
                html +='<a href="#" class="btn btn-default btn-sm" id="imp_btn" onclick="Imp()">导入</a>';

			if(new WebUser().No=="admin")
			    html +='<a href="#" class="btn btn-default btn-sm" id="setting_btn" onclick="Setting()">设置</a>';

            
                

			$("#toolbar").append(html);
			
        }
        
        function showBarTable(attrs,data){
            var html = "";
          
              if (attrs.length==0)
                  html +="<table style='width:30%;' >";

             if (attrs.length==1)
                 html +="<table style='width:50%;' >";

            if (attrs.length>1)
                html +="<table style='width:100%;' >";


             html +="<tr>";
             if (mapBase.IsShowSearchKey == "1"){
                 var keyLabel  = cfg.GetPara("KeyLabel");
                if(keyLabel == null || keyLabel == undefined || keyLabel =="")
                    keyLabel="关键字";
                html += "<td align='right'><label  style='text-align: right; margin-top:5px;margin-left:5px;' for='TB_Key'>"+keyLabel+":</label></td>";
                html +="<td align='left'><input style='width:100%;' type=text id='TB_Key' name='TB_Key' value='" + ur.SearchKey + "' class='form-control' /></td>";
            }
            if (mapBase.DTSearchWay != "0") {
                html += "<td align='right'><label style='text-align: right; margin-top:5px;padding-left:20px;'>" + mapBase.DTSearchLable + ":</label></td>";

                if (mapBase.DTSearchWay == "1") {
                    html += "<td align='left'><input type=text id='TB_DTFrom' name='TB_DTFrom' value='" + ur.DTFrom + "'  onfocus=\"WdatePicker({dateFmt:'yyyy-MM-dd'})\" style='width:120px;' class='form-control Wdate' /></td>";
                    html += "<td align='left'>&nbsp;<label>到</label>&nbsp;&nbsp<input type=text id='TB_DTTo' name='TB_DTTo' value='" + ur.DTTo + "' onfocus=\"WdatePicker({dateFmt:'yyyy-MM-dd'})\" style='width:120px;' class='form-control Wdate' /></td>";
                } else {
                    html += "<td align='left'><input type=text id='TB_DTFrom' name='TB_DTFrom' value='" + ur.DTFrom + "'  onfocus=\"WdatePicker({dateFmt:'yyyy-MM-dd HH:mm'});\" style='width:160px;' class='form-control Wdate' /></td>";
                    html += "<td align='left'>&nbsp;<label>到</label>&nbsp;&nbsp<input type=text id='TB_DTTo' name='TB_DTTo' value='" + ur.DTTo + "' onfocus=\"WdatePicker({dateFmt:'yyyy-MM-dd HH:mm'});\"  style='width:160px;' class='form-control Wdate' /></td>";
                }
            }
			

            //格式为: @WFSta=0@FK_Dept=02
            var json = AtParaToJson(ur.Vals);
            
            for (var i = 0; i < attrs.length; i++) {
            	 var attr = attrs[i];
                 var W = attr.Width;
				if(attr.Width>=1000){
                    html +="</tr>";
                    html +="<tr>";
                    W = 130;
                }

                html += "<td align='right'><label style='text-align: right; margin-top:5px;margin-left:5px;' for='DDL_" + attr.Field + "'>" + attr.Name + ":</label></td>";
                html += "<td align='left'><select class='form-control' style='margin-top:5px;width:100%;' name='DDL_" + attr.Field + "' ID='DDL_" + attr.Field + "'>" + InitDDLOperation(data, attr, "all") + "</select></td>";
            }
            
            //增加按钮.
            html += '<td align="left" colspan=2 ><a href="#"class="btn btn-primary btn-sm" style="margin-left:20px" id="search_btn" onclick="Search()">查询</a>  ';
            
            var btnLab1 = cfg.GetPara("BtnLab1");
            var btnLab2 = cfg.GetPara("BtnLab2");
            if(btnLab1 != null && btnLab1 != undefined && btnLab1 != "")
                html += "&nbsp;<a href='#'class='btn btn-default btn-sm'  onclick='executeFunction(\""+cfg.GetPara("BtnJS1")+"\",\""+btnLab1+"\")'>"+btnLab1+"</a>";

             if(btnLab2 != null && btnLab2 != undefined && btnLab2 != "")
                 html += "&nbsp;<a href='#'class='btn btn-default btn-sm'   onclick='executeFunction(\""+cfg.GetPara("BtnJS2")+"\",\""+btnLab2+"\")'>"+btnLab2+"</a>";

            if (mapBase.IsInsert.toString().toLowerCase() == "true")
                html += '&nbsp;<a href="#" class="btn btn-default btn-sm" id="new_btn" onclick="New()">新建</a>';
            
            html +='&nbsp;<a href="#" class="btn btn-default btn-sm" id="exp_btn" onclick="Exp()">导出</a>';

            if(mapBase.IsImp.toString().toLowerCase() == "true")
               html +='&nbsp;<a href="#" class="btn btn-default btn-sm" id="exp_btn" onclick="Imp()">导入</a> ';
            if(new WebUser().No=="admin")
			    html +='&nbsp;<a href="#" class="btn btn-default btn-sm" id="setting_btn" onclick="Setting()">设置</a>';
         
			html +="</td></tr>";

			html +="</table>";

			$("#toolbar").append(html);

             //为查询外键赋值.
            for (var i = 0; i < attrs.length; i++) {
                var attr = attrs[i];
                  var selectVal = json[attr.Field];

                if (selectVal == undefined || selectVal == "")
                    selectVal = "all";
                //判断是否有级联关系
                var myPK = "ActiveDDL_"+ensName+"_"+attr.Field;
                var mapExt = new Entity("BP.Sys.MapExt");
                mapExt.SetPKVal(myPK);
                var isExist = mapExt.RetrieveFromDBSources();
                //处理级联关系
                if(isExist == 1){
                    var ddlPerant = $("#DDL_" + mapExt.AttrOfOper);
                    var ddlChild = $("#DDL_" + mapExt.AttrsOfActive);
                    if (ddlPerant != null && ddlChild != null){
                        ddlPerant.attr("onchange", "DDLRelation(this.value,\'" + "DDL_" + mapExt.AttrsOfActive + "\', \'" + mapExt.MyPK + "\',\'" + ddlPerant.val() + "\')");
                       
                    }
                }

                $("#DDL_" + attr.Field).val(selectVal);
            }
        }

    

        //初始化下拉列表框的OPERATION
        function InitDDLOperation(frmData, mapAttr, defVal) {

            var operations = "";
            operations += "<option value='all' >全部</option>";

            var ens = frmData[mapAttr.Field];
            if (ens == null) {
                ens = [{ 'IntKey': 0, 'Lab': '否' }, { 'IntKey': 1, 'Lab': '是'}];
            }
            for (var i = 0; i < ens.length; i++) {

                var en = ens[i];

                if (en.No == undefined)
                    operations += "<option value='" + en.IntKey + "'>" + en.Lab + "</option>";
                else
                    operations += "<option value='" + en.No + "'>" + en.Name + "</option>";
            }
            return operations;
        }

        //执行查询.
        function Search() {

            //保存查询条件.
            var ensName = GetQueryString("EnsName");
            var ur = new Entity("BP.Sys.UserRegedit");
            ur.MyPK = webUser.No + "_" + ensName + "_SearchAttrs";
            ur.FK_Emp = webUser.No;

            if ($("#TB_Key") != null && $("#TB_Key").val() != "")
                ur.SearchKey = $("#TB_Key").val();
            else
                ur.SearchKey = "";

            //设置查询时间.
            if ($("#TB_DTFrom").length == 1)
                ur.DTFrom = $("#TB_DTFrom").val();

            if ($("#TB_DTTo").length == 1)
                ur.DTTo = $("#TB_DTTo").val();

            //获得外键的查询条件,存储里面去.
            var str = "";
            $("select[name^='DDL_']").each(function () {
                var id = $(this).attr("id");
                id = id.replace("DDL_", "");
                str += "@" + id + "=" + $(this).val();
            });

            ur.FK_Emp = webUser.No;
            ur.CfgKey = "SearchAttrs";
            ur.Vals = str;
            ur.FK_MapData = ensName;
            ur.SetPara("RecCount", count);
            var i = ur.Save();
            
            window.location.href = "?EnsName=" + ensName + "&PageIdx=1"  + "&PageSize=" + pageSize;
        }

    
        function SearchData() {
            //创建处理器.
            var handler = new HttpHandler("BP.WF.HttpHandler.WF_Comm");
            handler.AddUrlData()
            handler.AddPara("PageIdx", pageIdx);
            handler.AddPara("PageSize", pageSize);
            //handler.AddPara("EnsName", GetQueryString("EnsName"));

            //查询集合
            var data = handler.DoMethodReturnString("Search_SearchIt");
            if (data.indexOf('err@') == 0) {
                alert(data);
                return;
            }

            data = JSON.parse(data);
            //当前用户页面信息.
            var ur = new Entity("BP.Sys.UserRegedit");
            ur.MyPK = webUser.No + "_" + ensName + "_SearchAttrs";
            ur.RetrieveFromDBSources();

            count = ur.GetPara("RecCount");
            if (count%pageSize!=0)
                pages = parseInt(count / pageSize) + 1;
            else
                pages = parseInt(count / pageSize);

            if(pages == 0) pages =1;

             if (firstLoadTable){
                $('#dg').bootstrapTable("load",data["DT"]);
                return;
           }
            return data;
        }

        //生成查询页面..
        function BindTable() {
           
            //获取页面的高度
            var H = document.body.clientHeight;
            var tableH = H-$("#toolbar").outerHeight()-$("#page-nav").outerHeight()-70;

            if (pageIdx == "" || pageIdx == undefined)
                pageIdx = "1";
            if (pageSize == "" || pageSize == undefined)
                pageSize = "20";


            var mapdata = SearchData();
            var attrs = mapdata["Attrs"];

            var dtMs = mapdata["dtM"];

            var sysMapData = mapdata["Sys_MapData"][0];
            sysMapData = new Entity("BP.Sys.MapData", sysMapData); //把他转化成entity.
            var enPK = sysMapData.GetPara("PK");

            if (attrs == undefined) {
                alert('没有取得属性.');
                return;
            }

            var keyOfEn = "";

            var columns = new Array(); ;
           columns.push({
                title: '序',
                field: '',
                align: 'center',
                width:25,
                formatter: function (value, row, index) {
                    return pageSize * (pageIdx - 1) + index + 1;    // 返回每条的序号： 每页条数 *（当前页 - 1 ）+ 序号
                }
           });
            for (var i = 0; i < attrs.length; i++) {
                var attr = attrs[i];

                if (attr.UIVisible == 0
                || attr.KeyOfEn == "OID"
                || attr.KeyOfEn == "WorkID"
                || attr.KeyOfEn == "NodeID"
                || attr.KeyOfEn == "MyNum"
                || attr.KeyOfEn == "MyPK") {
                    keyOfEn = attr.KeyOfEn
                    continue;
                }


                var field = attr.KeyOfEn;
                var title = attr.Name;
                var width = attr.Width;
                if (attr.UIContralType == 1){
                    if(width==null || width==""|| width==undefined)
                        width = 180;
                    field = field + "Text";
                     columns.push({
                        field: field,
                        title: title,
                        fixed: false,
                        width:width,
                        cellStyle:{
                            css:{"white-space": "nowrap","word-break":"keep-all",  "width":"100%"}
                        }
                    });
                    continue;
                }
                if (attr.UIContralType == 2){
                    columns.push({
                        field: field,
                        title: title,
                        width:attr.Width,
                        fixed: false,
                        formatter: function (value, row, index) {
                            if (value == "0") return "否";
                            if (value == "1") return "是";
                        }
                    });
                    continue;
                }
                if(width==null || width==""|| width==undefined)
                    width = 100;
                columns.push({
                    field: field,
                    title: title,
                    width:attr.Width,
                    fixed: false

                });
            }
           
            //获取屏幕的长宽
           var W = document.body.clientWidth-40;
           var H = document.body.clientHeight-40;
            var entityAthType = sysMapData.GetPara("BPEntityAthType");
            if(dtMs.length>0 || entityAthType == 1 || entityAthType == 2){
                columns.push({
                    field: '_operate',
                    title: '操作',
                    width:200,
                    align:'center',
                    formatter: function(value,row,index){
                    var pkval = row[enPK];
                    var html = "";
                    for(var k = 0 ;k<dtMs.length;k++){
                        var dtm = dtMs[k];
                        var warning = dtm.Warning;
                        var refMethodType = parseInt(dtm.RefMethodType);
                        var url = dtm.Url+pkval;
                        switch(refMethodType){
                            case RefMethodType.LinkeWinOpen:
                                html += "<a href='#' onclick='WinOpenIt(\""+url+"\",\""+dtm.Title+"\")'>"+dtm.Title+"</a>&nbsp;&nbsp;";
                                break;
                            case RefMethodType.LinkModel:
                            case RefMethodType.RightFrameOpen:
                                html += "<a href='#' onclick='OpenBootStrapModal(\""+url+"\",\"eudlgframe\",\""+dtm.Title+"\","+W+","+H+",\"icon-property\", null, null, null, null, null, \"black\")'>"+dtm.Title+"</a>&nbsp;&nbsp;";
                                break;
                            case RefMethodType.Func:
                                    if (dtm.FunPara == true || dtm.FunPara == "true")
                                    html += "<a href='#' onclick='OpenBootStrapModal(\""+url+"\",\"eudlgframe\",\""+dtm.Title+"\","+W+","+H+",\"icon-property\", null, null, null, null, null, \"black\")'>"+dtm.Title+"</a>&nbsp;&nbsp;";
                                else {
                                    if (warning ==null || warning == "null" || warning == "")
                                    {
                                        warning = "确定要执行吗？";
                                    }
                                    else {
                                        warning = warning.replace(/,\s+/g, ",");
                                        warning = warning.replace(/\s+/g, "\r\n");
                                    }
                                    html += "<a href='#' onclick='openFun(\""+warning+"\",\""+url+"\",\""+dtm.Title+"\")'>"+dtm.Title+"</a>&nbsp;&nbsp;";
                       
                                }

                                    break;
                                default:break;
                            }
                        }
                        html += formatOper(value,row,index);
                        if(html == "")
                        html ="-";
                              
                    return html;
                              
                    }
                });
            }

            var isEnableOpen = cfg.GetPara("IsEnableOpenICON");
            //添加显示详情列
            if(isEnableOpen == "1"){
                //加入操作下载文件
                 columns.push({
                     field: 'viewDetail',
                     title: '详细信息',
                     width: 80,
                     align:'center',
                     formatter: function(value,row,index){
                        var pkval = row[enPK];
                        var paras = "&" + enPK + "=" + pkval;
                        for (var i = 0; i < attrs.length; i++) {
                            var attr = attrs[i];
                            if (attr.UIContralType == 1)
                                paras += "&" + attr.KeyOfEn + "=" + row[attr.KeyOfEn];
                        }

                        return "<a href='#' onclick='OpenEn(\""+pkval+"\",\""+paras+"\")'>详情</a>";
                     }
                 }); 
            }
           
            $('#dg').html("");
            $('#dg').bootstrapTable({
                data: mapdata["DT"],
                columns: [columns],
                cache:false,
                striped: true,
                height:tableH,
                singleSelect: true,
                sidePagination: "server",
                pageNumber: 1,
                strictSearch: true,
                //得到查询的参数
                queryParams: function (params) {
                    //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                    var temp = {
                        rows: 10,                         //页面大小
                        page: (count /10) + 1,   //页码

                    };
                    return temp;
                },

                onDblClickRow: function (row, $element) {
                    var pkval = row[enPK];
                    var paras = "&" + enPK + "=" + pkval;
                    for (var i = 0; i < attrs.length; i++) {
                        var attr = attrs[i];
                        if (attr.UIContralType == 1)
                            paras += "&" + attr.KeyOfEn + "=" + row[attr.KeyOfEn];
                    }

                    OpenEn(pkval, paras);
                }

            });  
             firstLoadTable = true;

     }
  
     //分页功能
    function Paginator(pageCount,currentPage) {
        var pageCount = pageCount; //取到pageCount的值(把返回数据转成object类型)
        var options = {
            bootstrapMajorVersion: 3, //版本
            currentPage: currentPage, //当前页数
            totalPages: pageCount, //总页数
            shouldShowPage: true, //是否显示该按钮
            itemTexts: function (type, page, current) {
                switch (type) {
                    case "first":
                        return "首页";
                    case "prev":
                        return "上一页";
                    case "next":
                        return "下一页";
                    case "last":
                        return "末页";
                    case "page":
                        return page;
                }
            }, //点击事件，用于通过Ajax来刷新整个list列表
            onPageClicked: function (event, originalEvent, type, page) {
                pageIdx = page;
                SearchData(page);
               $('#page_info').html("").append("<li class='disabled controls'>当前第" + pageIdx + "页，总共" + pages +
                                "页,总共"+count+"条记录。</li>");
            }
        };
        $('#page_nav').bootstrapPaginator(options);
        $('#page_info').append("<li class='disabled controls'>当前第" + pageIdx + "页，总共" + pages +
                                "页,总共"+count+"条记录。</li>");
        
    }
   
     
        function operate(value, row, index) {
            return '<a href="#" onclick="editUser(' + index + ')">查看明细</a>';
        }

        function OpenEn(pk, paras) {

            var ensName = GetQueryString("EnsName");
            var enName = ensName.substring(0, ensName.length - 1);
            //考虑兼容旧版本.
            var url = cfg.GetPara("WinOpenUrl");
            if (url && url.length >4)
            {
               cfg.Url=url;
               cfg.Update();
            }
            
            url= cfg.Url;
            var urlOpenType=cfg.GetPara("SearchUrlOpenType");

            if (urlOpenType == 0 || urlOpenType==undefined)
                url = "./RefFunc/En.htm?EnName=" + mapBase.EnName + "&PKVal=" + pk;

            if (urlOpenType==1)
                url = "./RefFunc/EnOnly.htm?EnName=" + mapBase.EnName + "&PKVal=" + pk;

            if (urlOpenType == 2)
                url = "../CCForm/FrmGener.htm?FK_MapData=" +GetQueryString("EnsName") + "&PKVal=" + pk;

            if (urlOpenType == 3)
                url = "../CCForm/FrmGener.htm?FK_MapData=" + GetQueryString("EnsName") + "&PKVal=" + pk;

            if (urlOpenType==9)
            {
                if (url.indexOf('?') == -1)
                    url = url + "?1=1";
                url = url + "&EnsName=" + ensName + "&EnName=" + enName + "&PKVal=" + pk + paras;
            }

            var windowW = cfg.GetPara("WinCardW");
            if (windowW == "" || windowW == undefined)
                windowW = 900;

            var windowH = cfg.GetPara("WinCardH");
            if (windowH == "" || windowH == undefined)
                windowH = 500;

            var localUrl = window.location.href;


            var localArr = new Array();
            localArr = localUrl.split("&");
            if (localArr.length == 1) {
                localUrl = localUrl + "&PageIdx=" + pageIdx + "&PageSize=" + pageSize;
            } else {
                for (var i = 0; i < localArr.length; i++) {
                    if (localArr[i].indexOf("PageIdx") != -1) {
                        localArr[i] = "PageIdx=" + pageIdx;
                    }
                    if (localArr[i].indexOf("PageSize") != -1) {
                        localArr[i] = "PageSize=" + pageSize;
                    }
                }
                localUrl = "";
                for (var i = 0; i < localArr.length; i++) {
                    localUrl += localArr[i];
                    if (i != localArr.length - 1) localUrl += "&";
                }
            }

            OpenBootStrapModal(url, "eudlgframe", mapBase.EnDesc + ' : 详细', windowW, windowH, "icon-property", null, null,  null, function () {
                window.location.href = localUrl;
            },null,'black');
        }

        function New() {
            OpenEn("");
        }

        function Exp() {
            var handler = new HttpHandler("BP.WF.HttpHandler.WF_Comm");
            handler.AddPara("EnsName", GetQueryString("EnsName"));
            //查询集合
            var data = handler.DoMethodReturnString("Search_Exp");
            var url = "";
            if (data.indexOf('err@') == 0) {
                alert(data);
            }
            if (plant != 'CCFlow') {
                var currentPath = window.document.location.href;
                var path = currentPath.substring(0, currentPath.indexOf('/WF') + 1);
                data = path + data;
            }
            window.open(data);
            return;

        }

        function Imp(){
           var user = new WebUser();
           var url = "./Sys/ImpData.htm?EnsName=" + GetQueryString("EnsName") + "&m=" + Math.random();
           //获取屏幕的长宽
           var W = document.body.clientWidth-80;
           var H = document.body.clientHeight-120;
           OpenBootStrapModal(url, "eudlgframe", '导入数据', W, H, "icon-property", null, null, null, function(){
             window.location.href= window.location.href;
           }, null, 'black'); 
        }

        function Setting() {
            var user = new WebUser();
            var url = "./Sys/SearchSetting.htm?EnsName=" + GetQueryString("EnsName") + "&m=" + Math.random();
            //获取屏幕的长宽
           var W = document.body.clientWidth-340;
           var H = document.body.clientHeight-40;
            OpenBootStrapModal(url, "eudlgframe", '设置', W, H, "icon-property", null, null, null, null, null, 'black'); 
        }

        function formatOper(val,rowData,index){
            var pkval = rowData["No"];
            if (pkval == undefined) {
                pkval = rowData["OID"];
            }
            if (pkval == undefined) {
                pkval = rowData["MyPK"];
            }
            if (pkval == undefined) {
                pkval = rowData["WorkID"];
            }
            if (pkval == undefined) {
                pkval = rowData["NodeID"];
            }

             if (rowData.MyFileName != null && rowData.MyFileName != "")
                return "<a href='#' onclick='downLoadFile(\"" + pkval + "\")' target='_self'>下载</a>";
            else
                return ""; 
        }

        function openFun(warning,url,title){
            var W = document.body.clientWidth-40;
           var H = document.body.clientHeight-40;
            if(confirm(warning)){
               OpenBootStrapModal(url,"eudlgframe",title,W,H,"icon-property", null, null, null, null, null, "black"); 
            }
        }

        function downLoadFile(PKVal) {
            if (plant == "CCFlow")
                window.location.href = '../CCForm/DownFile.aspx?DoType=EntityFile_Load&DelPKVal=' + PKVal + '&EnsName=' + GetQueryString("EnsName");
            else {
                var currentPath = window.document.location.href;
                var path = currentPath.substring(0, currentPath.indexOf('/WF') + 1);
                Url = path + '/WF/CCForm/EntityFileLoad.do?DelPKVal=' + PKVal + '&EnsName=' + GetQueryString("EnsName");
                window.location.href = Url;
            }
        }

       function executeFunction(jsString,label){
         jsString = jsString.replace(/~/g, "'");
         if(jsString.indexOf("/")!=-1){
             var W = document.body.clientWidth-40;
             var H = document.body.clientHeight-40;
            OpenBootStrapModal(jsString, "eudlgframe", label, W, H, "icon-property", null, null, null, null, null, 'black'); 
          }else{
            if (jsString.indexOf('(') == -1)
                eval(jsString + "()");
            else
                eval(jsString);
          }
       }

       /* 级联下拉框  param 传到后台的一些参数  例如从表的行数据 主表的字段值 如果param参数在，就不去页面中取KVS 了，PARAM 就是*/
    function DDLRelation(selectVal, ddlChild, fk_mapExt, param) {
        if (selectVal == "all") {
            $("#" + ddlChild).empty();
            //无数据返回时，提示显示无数据，并将与此关联的下级下拉框也处理一遍，edited by liuxc,2015-10-22
            $("#" + ddlChild).append("<option value='all' selected='selected' >全部</option");
            var chg = $("#" + ddlChild).attr("onchange");

            $("#" + ddlChild).change();

            return;
        }

        var mapExt = new Entity("BP.Sys.MapExt", fk_mapExt);

        //处理参数问题
        if (param != undefined) {
            kvs = '';
        }
        var dbSrc = mapExt.Doc;
        if (param != undefined) {
            for (var pro in param) {
                if (pro == 'DoType')
                    continue;
                dbSrc = dbSrc.replace("@" + pro, param[pro]);
            }
        }

        var dataObj = GenerDB(dbSrc, selectVal, mapExt.DBType); //获得数据源.

        // 这里要设置一下获取的外部数据.
        // 获取原来选择值.
        var oldVal = null;
        var ddl = document.getElementById(ddlChild);

        if (ddl == null) {
            alert(ddlChild + "丢失,或者该字段被删除.");
            return;
        }


        var mylen = ddl.options.length - 1;
        while (mylen >= 0) {
            if (ddl.options[mylen].selected) {
                oldVal = ddl.options[mylen].value;
            }
            mylen--;
        }

        //清空级联字段
        $("#" + ddlChild).empty();

        //查询数据为空时为级联字段赋值
        if (dataObj == null || dataObj.length == 0) {
            //无数据返回时，提示显示无数据，并将与此关联的下级下拉框也处理一遍，edited by liuxc,2015-10-22
            $("#" + ddlChild).append("<option value='' selected='selected' >无数据</option");
            var chg = $("#" + ddlChild).attr("onchange");

            if (typeof chg == "function") {
                $("#" + ddlChild).change();
            }
            return;
        }

        //不为空的时候赋值
         $("#" + ddlChild).append("<option value='all' >全部</option>");
        $.each(dataObj, function (idx, item) {

            //  alert(item[idx][1]);
            //console.log(item);
            //return;

            var no = item.No;
            if (no == undefined)
                no = item.NO;

            var name = item.Name;
            if (name == undefined)
                name = item.NAME;

            $("#" + ddlChild).append("<option value='" + no + "'>" + name + "</option");

        });

        var isInIt = false;
        mylen = ddl.options.length - 1;
        while (mylen >= 0) {
            if (ddl.options[mylen].value == oldVal) {
                ddl.options[mylen].selected = true;
                isInIt = true;
                break;
            }
            mylen--;
        }
        if (isInIt == false) {
            //此处修改，去掉直接选中上次的结果，避免错误数据的产生，edited by liuxc,2015-10-22
            //$("#" + ddlChild).prepend("<option value='' selected='selected' >*请选择</option");
            $("#" + ddlChild).val('');
            //增加默认选择第一条数据
            ddl.options[0].selected = true;
            var chg = $("#" + ddlChild).attr("onchange");
            $("#" + ddlChild).change();
       
        }
    }
           //打开窗口
    function WinOpenIt(url, winName) {
        //var w = screen.availWidth;
        //var h = screen.availHeight;
        var newWindow = window.open(url, winName, 'height=1200,width=1000,top=' + (window.screen.availHeight - 800) / 2 + ',left=' + (window.screen.availWidth - 1030) / 2 + ',scrollbars=yes,resizable=yes,toolbar=false,location=false,center=yes,center: yes;');
        newWindow.focus();
        return;
    }
   

    </script>
    <style type="text/css">
        body
        {
            margin: 0px;
        }
        .panel-header, .panel-body
        {
            border-width: 1px;
            border-top: 0px;
            border-left: 0px;
            border-right: 0px;
        }
        
        .table
        {
            table-layout: fixed;
        }
        
        table > td
        {
            width: 100%;
        }
        .pagination
        {
            margin: 8px 0;
            display: block;
            font-size: 13px;
        }
        .pagination .controls
        {
            float: left;
            border: 0;
            padding: 7px 0 0 15px;
            color: #777;
        }
    </style>
</head>
<body id="SearchHtml">
    <div class="wrapper wrapper-content animated fadeInRight" style="padding: 0px 10px 0px 10px">
        <div class="ibox-content">
            <div class="row">
                <div class="panel panel-default" style="border: 0px; margin-bottom: 3px">
                    <div id="toolbar" style="width: 100%">
                    </div>
                </div>
            </div>
            <div class="row">
                <table id="dg" class="table table-hover" style="word-wrap: break-word; word-break: break-all;">
                </table>
            </div>
            <!-- 显示分页信息 -->
            <div class="row" style="text-align: left;">
                <ul class="pagination" id="page_nav">
                </ul>
                <ul class="pagination controls" id="page_info">
                </ul>
                <div style="clear: both;">
                </div>
            </div>
        </div>
        <div id="Msg">
        </div>
    </div>
</body>
</html>
